package com.apexwear.apexutils.data;

import android.text.TextUtils;
import android.util.Log;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.apex.bluetooth.callback.GeneralCallback;
import com.apex.bluetooth.callback.WatchInfoCallback;
import com.apex.bluetooth.core.EABleManager;
import com.apex.bluetooth.enumeration.QueryWatchInfoType;
import com.apex.bluetooth.model.EABleWatchInfo;
import com.apex.jieli.watcha.JieliDialCallback;
import com.apex.jieli.watcha.JieliWatchFaceManager;
import com.apex.jieli.watcha.JieliWatchInfo;
import com.jieli.jl_rcsp.model.base.BaseError;

import java.util.List;

public class Jieli707Dial extends ViewModel {
    final String TAG = this.getClass().getSimpleName();
    public MutableLiveData<List<JieliWatchInfo>> infoLive = new MutableLiveData<>();

    public void getWatchFaceData() {
        /**
         EABleManager.getInstance().queryWatchInfo(QueryWatchInfoType.watch_info, new WatchInfoCallback() {
        @Override public void watchInfo(EABleWatchInfo eaBleWatchInfo) {
        if (eaBleWatchInfo != null && eaBleWatchInfo.getLcd_pixel_type() == 4) {
         */
        Log.e(TAG, "开始707获取表盘信息");
        JieliWatchFaceManager.getInstance().getDialList(new JieliDialCallback() {
            @Override
            public void jieliDial(List<JieliWatchInfo> list) {
                if (infoLive != null) {
                    infoLive.postValue(list);
                }
            }

            @Override
            public void error(BaseError baseError) {
                Log.e(TAG, "获取表盘失败");

            }
        });
        /**
         }
         }

         @Override public void mutualFail(int i) {

         }
         });
         */
    }

    public void deleteWatchface(List<JieliWatchInfo> infos) {
        if (infos == null || infos.isEmpty()) {
            return;
        }
        delete(infos);
    }

    private void delete(final List<JieliWatchInfo> infos) {
        if (infos == null || infos.isEmpty()) {
            getWatchFaceData();
            return;
        }
        JieliWatchInfo jieliWatchInfo = infos.remove(0);
        if (jieliWatchInfo == null || TextUtils.isEmpty(jieliWatchInfo.path)) {
            delete(infos);
        } else {
            JieliWatchFaceManager.getInstance().deleteWatchFace(jieliWatchInfo.path, new GeneralCallback() {
                @Override
                public void result(boolean b, int i) {
                    delete(infos);
                }

                @Override
                public void mutualFail(int i) {
                    delete(infos);
                }
            });
        }
    }

}
